import { BaseRequest, BaseResponse } from 'tsrpc'

// === 基础配置类型 ===
export interface ConfigItemBase {
    id: string
    name: string
    description?: string
    version?: string
    enabled?: boolean
    tags?: string[]
    lastModified?: number
    author?: string
}

// === 装备配置 ===
export interface EquipmentTemplate extends ConfigItemBase {
    sys: string
    type: string
    job: string
    solt: string
    icon: string
    emoji: string
    source?: string
    quality: {
        min: number
        max: number
        weights?: number[]
    }
    baseAttributes: AttributeConfig[]
    skillPools: SkillPools
    creator?: string
}

export interface AttributeConfig {
    key: string
    min: number
    max: number
    growthType?: 'linear' | 'exponential' | 'logarithmic'
    qualityMultiplier?: number
}

export interface SkillPools {
    inherent: SkillConfig[]
    enchantable: EnchantableSkillPool[]
    exclusive?: ExclusiveSkillUnlock[]
}

// === 技能配置 ===
export interface SkillConfig extends ConfigItemBase {
    skillId: string
    reName?: string
    desc?: string
    type?: 'active' | 'passive' | 'aura'
    targetTypes?: string[]
    cooldown?: number
    level?: number
    maxLevel?: number
    exp?: number
    useCount?: number
    quality?: number
    category?: string
    classType?: string
    notBuy?: boolean
    effects?: string[]
    effect?: string[]
    data?: ISkillEffectData[]
    permanentBoost?: IPermanentBoostConfig
    buffs?: IBuffConfig[]
    triggerConditions?: Record<string, any>
    prerequisites?: string[]
    customData?: Record<string, any>
}

export interface ISkillEffectData {
    attRange?: number
    fixed?: number
    shield?: number
    healing?: number
    attributeModify?: Record<string, number>
    statusEffect?: IStatusEffectConfig
    permanentBoost?: IPermanentBoostConfig
    [key: string]: any
}

export interface IPermanentBoostConfig {
    type: string
    amount: number
    maxBoosts?: number
    condition?: string
    conditionParams?: Record<string, any>
    conditionDesc?: string
}

export interface IBuffConfig {
    id: string
    duration: number
    maxStacks?: number
    value?: number
}

export interface IStatusEffectConfig {
    type: string
    duration: number
    intensity?: number
}

export interface EnchantableSkillPool {
    skill: SkillConfig
    weight: number
    conditions?: EnchantCondition
    maxCount?: number
}

export interface EnchantCondition {
    minLevel?: number
    requiredTalent?: string
    requiredQuest?: string
    customCheck?: string
}

export interface ExclusiveSkillUnlock {
    skill: SkillConfig
    unlock: {
        type: 'quest' | 'achievement' | 'event' | 'custom'
        requirement: string
        description?: string
    }
}

// === 配置集合 ===
export interface ConfigCollection<T = any> {
    version: string
    lastUpdated: number
    data: T[]
    metadata?: {
        author?: string
        description?: string
        changelog?: string[]
    }
}

// === 验证结果 ===
export interface ValidationResult {
    isValid: boolean
    errors: ValidationError[]
    warnings: ValidationWarning[]
    validatedCount: number
}

export interface ValidationError {
    id: string
    field?: string
    message: string
    severity: 'error' | 'warning' | 'info'
}

export interface ValidationWarning extends ValidationError {
    suggestion?: string
}

// === 配置列表项 ===
export interface ConfigListItem {
    type: string
    name: string
    description: string
    count: number
    lastModified: number
    size: string
    status: 'healthy' | 'warning' | 'error'
}

// === 统计信息 ===
export interface ConfigStats {
    totalConfigs: number
    configsByType: Record<string, number>
    lastModified: number
    healthStatus: 'healthy' | 'warning' | 'error'
    validationScore: number
    memoryUsage?: string
}

// === 导入导出选项 ===
export interface ImportOptions {
    format: 'xlsx' | 'json' | 'yaml'
    merge?: boolean
    validate?: boolean
    backup?: boolean
}

export interface ExportOptions {
    format: 'xlsx' | 'json' | 'yaml' | 'typescript'
    minify?: boolean
    includeComments?: boolean
    selectedTypes?: string[]
}

// === API 响应基础类型 ===
export interface ConfigEditorResponse<T = any> extends BaseResponse {
    data?: T
    errors?: string[]
    warnings?: string[]
}
